import { defineStore } from 'pinia';
import { login as apiLogin } from '../api/auth';

export const useUserStore = defineStore('user', {
    state: () => ({
        token: null,
        userType: null,
    }),
    actions: {
        async login(username, password) {
            const response = await apiLogin(username, password);
            this.token = response.data.token;
            this.userType = response.data.userType;
        },
        logout() {
            this.token = null;
            this.userType = null;
        },
    },
    persist: true,
});